<?php

include ("configs/config.php");
$tpl = new XTemplate("./template/tpl_admin.html"); 


	
	//$incoming_url=www.xxxxxx.com/org
	
 
	$SQLselect="select * from url_address where url='".$incoming_url."'";
	$SQLinsert=mysql_query($SQLselect);	
	//echo $SQLselect;
	
	
	if(mysql_fetch_array($SQLinsert)=="")
		{
		echo "<h3>You do not have the permission to see this page</h3>";
		}
		
	else
		{
		//for this url we find: 
			
				
				$query_in="select incoming_views, new_views from incoming_links where url='" .$incoming_url."'";//cliks in
				$request_in=mysql_query($query_in);				
				$thisU=mysql_fetch_array($request_in);
				//echo $thisU['incoming_views'];
				if($thisU['incoming_views']==""){$no_url_in=0;}
				else {$no_url_in=$thisU['incoming_views'];}	
				if($thisU['new_views']==""){$new_no_url_in=0;}
				else {$new_no_url_in=$thisU['new_views'];}	
				//echo $query_in;	
				
				$query_out="select sum(views) views, sum(new_views) as new_views from redirected_links where url_site='".$incoming_url."'";//click out
				$request_out=mysql_query($query_out);	
				$thisU=mysql_fetch_array($request_out);
				if($thisU['views']==""){$no_url_out=0;}
				else {$no_url_out=$thisU['views'];}
				if($thisU['new_views']==""){$new_no_url_out=0;}
				else {$new_no_url_out=$thisU['new_views'];}
			
			
			
				if($no_url_in!=0&&$no_url_out!=0)
				{
					if($no_url_in>$no_url_out)//if in>out...
					{
						$rez=$no_url_in/$no_url_out;		
						$percent=round(100*$rez,0)."%";							
					}
					else
					{		
						$rez=$no_url_out/$no_url_in;	
						$percent=round(100*$rez,0)."%";				
					}
					
				}	
				elseif($no_url_in==0)
				{
					$percent="No incoming";					
				}
				elseif($no_url_out==0)
				{
					$percent="No outgoing";						
				}
				else
				{
					$percent="No cliks";		
				}
//--------------------------- the same thing for the new views				
				
				if($new_no_url_in!=0&&$new_no_url_out!=0) 
				{
					if($new_no_url_in>$new_no_url_out)//if in>out...
					{
						$new_rez=$new_no_url_in/$new_no_url_out;		
						$new_percent=round(100*$rez,0)."%";	
					
					}
					else
					{		
						$new_rez=$new_no_url_out/$new_no_url_in;	
						$new_percent=round(100*$rez,0)."%";	
					}
					
				}	
				elseif($new_no_url_in==0 && $new_no_url_out!=0)
				{
					$new_percent="No incoming";					
				}
				elseif($new_no_url_out==0 && $new_no_url_in!=0)
				{
					$new_percent="No outgoing";						
				}
				else
				{
					$new_percent="No cliks";		
				}
				
				
				
					
					
					
					
					if($thisUrl['url']=="unknown_url"){$thisUrl['url']="unknown_url_or_the_same";}
					$tpl->assign("site",$incoming_url);
					$tpl->assign("in",$no_url_in);
					$tpl->assign("new_in",$new_no_url_in);
					$tpl->assign("out",$no_url_out);
					$tpl->assign("new_out",$new_no_url_out);
					$tpl->assign("ratio",$percent);		
					$tpl->assign("new_ratio",$new_percent);
				$tpl->parse("main.body.public_stats.row");			
				
			
			
			
			
		}	
 
$tpl->parse("main.body.public_stats");
$tpl->parse("main.body");
$tpl->parse("main");
$tpl->out("main");



?>
